@echo off
setlocal enabledelayedexpansion

call pciex.cmd

set "version="
for /f "tokens=2 delims== " %%A in ('findstr /r /c:"^version =" pack.toml') do (
    set "version=%%A"
    set "version=!version:~1,-1!"
)

for /f "tokens=1-7 delims=-." %%A in ("%version%") do (
    set "part1=%%A"
    set "part2=%%B"
    set "part3=%%C"
    set "part4=%%D"
    set "part5=%%E"
    set "part6=%%F"
    set "part7=%%G"
)

set /a part7+=1
set "newversion=%part1%.%part2%-%part3%.%part4%.%part5%-%part6%.%part7%"

git add .
git commit -m "%version%"
git push -u origin main

set "quotedversion="%version%""

(for /f "delims=" %%A in (pack.toml) do (
    set "line=%%A"
    setlocal enabledelayedexpansion
    if "!line!"=="version = %quotedversion%" (
        echo version = "%newversion%"
    ) else (
        echo !line!
    )
    endlocal
)) > pack_temp.toml

move /y pack_temp.toml pack.toml

echo The new version is %newversion%
call pcire.cmd
endlocal